﻿using System;
using System.Threading;
using System.Threading.Tasks;
using Loki.UI;
using NUnit.Framework;

namespace Loki.Core.Test.Threads
{
    [TestFixture]
    public class UIContextTest : AssertionHelper
    {
        private Thread mainThread;

        public UIContextTest()
        {
            mainThread = Thread.CurrentThread;
        }

        [Test]
        public void TestConsoleInvoke()
        {
            UIContext.GetFromCurrentThread();

            int backid = 0;
            int tid = Thread.CurrentThread.ManagedThreadId;
            int taskid = 0;
            Action toUIThread = () => { backid = Thread.CurrentThread.ManagedThreadId; };
            Action backAction = () => { taskid = Thread.CurrentThread.ManagedThreadId; UIContext.Threading.OnUIThread(toUIThread); };
            var task = Task.Factory.StartNew(backAction);
            task.Wait();

            Expect(backid, Is.Not.EqualTo(tid));
            Expect(taskid, Is.EqualTo(backid));
        }
    }
}